package com.yc.fruitmarket.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.yc.fruitmarket.biz.typeBiz;
import com.yc.fruitmarket.biz.impl.typeBizImpl;

@WebServlet("/typeController/*")
public class typeController extends BaseServlet {
	private typeBiz tb = new typeBizImpl();
		
		//上架商品
		public void up(HttpServletRequest req, HttpServletResponse resp) {
			String tid = req.getParameter("tid");
			int result = tb.up(tid);
			this.send(resp, result);
		}
		
		//下架商品
		public void down(HttpServletRequest req, HttpServletResponse resp) {
			String tid = req.getParameter("tid");
			int result = tb.down(tid);
			this.send(resp, result);
		}
		
		//添加类别
		public void add(HttpServletRequest req, HttpServletResponse resp) {
			String name = req.getParameter("name");
			int result = tb.add(name);
			this.send(resp, result);
		}
		
		//获得类别
		public void gettype(HttpServletRequest req, HttpServletResponse resp) {
			List<Map<String, String>> list = tb.gettype();
			for(Map<String, String> map : list) {
				map.put("value", map.get("tname"));
			}
			this.send(resp, list);
		}
		
		//修改类别信息
		public void updatetype(HttpServletRequest req, HttpServletResponse resp) {
			int tid = Integer.parseInt(req.getParameter("tid"));
			String tname = req.getParameter("tname");
			int result = tb.updatetype(tid, tname);
			this.send(resp, result);
		}
		
		//条件查询
		public void getbytype(HttpServletRequest req, HttpServletResponse resp) {
			String tname = req.getParameter("tname");
			String status = req.getParameter("status");
			List<Map<String, String>> list = tb.getbytype(tname, status);
			this.send(resp, list);
			
		}

	//查询上架已有的类别
	public void findTypes(HttpServletRequest req, HttpServletResponse resp) {
		List<Map<String, String>> list = tb.findTypes();
		for(int i = 0; i < list.size(); i++) {
	 		list.get(i).put("checked", "true");
	 	}
		this.send(resp, list);
	}

//		//查询上架已有的类别
//		public void findTypes(HttpServletRequest req, HttpServletResponse resp) {
//			List<Map<String, String>> list = tb.findTypes();
//			this.send(resp, list);
//		}

	
}
